package com.bocloud.cmp.service.resource;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bocloud.cmp.dao.ResourceEventDao;
import com.bocloud.cmp.entity.resource.ResourceEvent;
import com.bocloud.cmp.interfaces.resource.ResourceEventService;
import com.bocloud.common.model.BsmResult;
import com.bocloud.common.model.GridBean;
import com.bocloud.common.model.Param;
import com.bocloud.common.utils.Common;
import com.bocloud.common.utils.GridHelper;
import com.bocloud.soc.dao.intf.UserDao;
import com.bocloud.soc.entity.User;
import com.google.common.collect.Maps;

/**
 * 资源事件Service接口实现
 * 
 * @author dongkai
 *
 */
@Service("resourceEventService")
public class ResourceEventServiceImpl implements ResourceEventService {

	private static Logger logger = LoggerFactory.getLogger(ImageServiceImpl.class);
	@Autowired
	private ResourceEventDao resourceEventDao;
	@Autowired
	private UserDao userDao;

	@Override
	public BsmResult list(int page, int rows, List<Param> params, Map<String, String> sorter, Boolean simple) {
		try {
			if (null == sorter) {
				sorter = Maps.newHashMap();
			}
			sorter.put("gmtOperate", Common.ONE);
			List<ResourceEvent> list = resourceEventDao.list(page, rows, params, sorter);
			for (ResourceEvent resEvent : list) {
				User user = userDao.query(resEvent.getOperatorId());
				resEvent.setOperator(user.getName());
			}
			int total = resourceEventDao.count(params);
			GridBean gridBean = GridHelper.getBean(page, rows, total, list);
			return new BsmResult(true, gridBean, "查询成功");
		} catch (Exception e) {
			logger.error("list resourceEvent failure:", e);
			return new BsmResult(false, "查询失败", null, null);
		}
	}

}
